#include <vector>
#include <memory>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <thread>
#include <cstdio>
#include <sys/epoll.h>
#include <string.h>
#include <unistd.h>
#include <cstring>
#include <sys/stat.h>
#include <errno.h>
#include "Request.h"
#include "Response.h"
#include "HTTP.h"

class Server{
public:
    Server(int port=8000,int listen_num=1024){
        events=new(std::nothrow) epoll_event[listen_num];
        if(events==nullptr){
            printf("Server init bad. events new bad.");
            abort();
        }
        epfd=epoll_create(10);
        if(epfd<0){
            printf("epfd create bad...\n");
            delete[] events;
            abort;
        }
        PORT=port;
        listen_num=listen_num;
        printf("init...\n");
    }
    int run();
    const int get_server_fd() const{
        return server_fd;
    }
    int get_server_fd(){
        return server_fd;
    }
    int get_epfd(){
        return epfd;
    }
    // void Server_accept(void); // listen connect.
    int request();
    ~Server(){
        delete[] events;
    }
private:
    int server_fd;
    int epfd;  // Server's epoll's filefd.
    int listen_num;  // Decide listen's size and epoll's event size.
    struct sockaddr_in server_addr;
    unsigned int PORT;
    struct epoll_event *events;  // this is epool's events. it's size look listen_nums.

};
